home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / dec92.zip / 1012057A < prev    next >
Text File  |  1992-10-09  |  7KB  |  331 lines

  1. PAGE ,132
  2. title VxD2B.ASM - Example Device Driver #2b
  3. ;EM    VxD2B - Example Device Driver #2b
  4. ;
  5. ;    Copyright 1992, Cherry Hill Software
  6. ;    All rights reserved.
  7. ;
  8. ;    SUMMARY
  9. ;        This driver simulates an interrupting device.  The control
  10. ;        port (output) has the following bit assignments:
  11. ;
  12. ;        Bit 0 - Start I/O.  Writing a zero to this bit begins
  13. ;            I/O transfer.  The "transfer" takes approximately
  14. ;            one-tenth of a second.    Writing a one to this
  15. ;            bit has no effect.
  16. ;
  17. ;        Bit 1 - Send EOI to device.  Writing a zero to this bit
  18. ;            sends End-of-Interrupt to the device and removes
  19. ;            any pending interrupt request.    Writing a one to
  20. ;            this bit has no effect.
  21. ;
  22. ;        All other bits: Always must write ones for future
  23. ;                compatibility.
  24. ;
  25. ;        When reading the port, the following is returned:
  26. ;
  27. ;        Bit 0 - initially set, this is reset when output port bit
  28. ;            1 is reset and is set when the interrupt request
  29. ;            is asserted.  This bit is zero when the device
  30. ;            is transferring data and is set to indicate
  31. ;            transfer complete.
  32. ;
  33. ;        Bit 1 - initially set, this is reset when the interrupt
  34. ;            request is asserted and is reset when the device
  35. ;            removes the interrupt request.    This bit is zero
  36. ;            to indicate a pending interrupt and is set if
  37. ;            no interrupt is pending.
  38. ;
  39. ;        All other bits: ignore returned value for future
  40. ;                compatibility.
  41. ;
  42. ;    WARNINGS
  43. ;
  44. ;
  45.     .386p
  46.  
  47.  
  48. .xlist
  49. include vmm.inc
  50. include debug.inc
  51. include v86mmgr.inc
  52. include vpicd.inc
  53. include ..\include\bogus.inc
  54. .list
  55.  
  56. VM_Not_Executable equ VM_Not_Executeable ; acckk!
  57.  
  58. subttl    VxD Declaration/Definition
  59. page
  60.  
  61. VxD2B_Init_Order equ VNETBIOS_Init_Order+100 ; Do this after the Virtual net
  62. VxD2B_Device_ID equ Bogus_Device_ID
  63.  
  64.  
  65. Declare_Virtual_Device VXD2, 1, 0, VxD2B_Control, VxD2B_Device_ID, \
  66.                VxD2B_Init_Order
  67.  
  68.  
  69. VxD_DATA_SEG
  70.  
  71. ;
  72. ;   Virtual Interrupt Descriptor Structure
  73. ;
  74. ;   We pass this to VPIDC_Virtualize_IRQ.  Here we specify the
  75. ;   interrupt level, the hardware interrupt procedure, and the procedures
  76. ;   that VPICD calls when the interrupt is dispatched into the VM and
  77. ;   when the VM returns from the interrupt.
  78. ;
  79. IRQD VPICD_IRQ_Descriptor <FAKE_IRQ,,,OFFSET32 VxD2_VInt_Proc,\
  80.                ,\
  81.                OFFSET32 VxD2_Mask_Change_Proc,\
  82.                OFFSET32 VxD2_IRET_Proc>
  83.  
  84. hIRQ        dd    -1        ; IRQ handle
  85. hOwner        dd    -1        ; Owning VM handle
  86. hTimeout    dd    0        ; handle to timeout callback (0=>none)
  87. bFakeData   db    01111111b   ; Fake I/O port data
  88.  
  89. VxD_DATA_ENDS
  90.  
  91.  
  92.  
  93. subttl Dispatch VxD Control
  94. page
  95. VxD_LOCKED_CODE_SEG
  96.  
  97. BeginProc CheckOwner, NO_LOG
  98.     cmp    ebx,hOwner
  99.     jne    short co1
  100.     ret                ; exit if owner is calling
  101. co1:
  102.     cmp    hOwner,-1
  103.     jne    short co2        ; skip if non-owner calling
  104.     mov    hOwner,ebx        ; set the owner
  105.     ret
  106. co2:
  107.     mov    al,-1
  108.     ret
  109. EndProc CheckOwner
  110.  
  111.  
  112. BeginProc TimeoutProc
  113.     mov    hTimeout,0        ; clear the handle
  114.     cmp    edx,hOwner        ; Still the same owner?
  115.     jne    short to1        ; skip if not
  116.     test    bFakeData,FAKE_STAT_BUSY    ; I/O pending?
  117.     jnz    short to1        ; skip if not
  118.     cmp    hOwner,-1        ; Do we have an owner?
  119.     je    short to1        ; skip if not
  120.     mov    eax,hIRQ
  121.     mov    ebx,hOwner
  122.     VxDcall VPICD_Set_Int_Request    ; assert the interrupt
  123.     mov    al,bFakeData
  124.     and    al,NOT (FAKE_STAT_IRQ)    ; indicate so in status port
  125.     or    al,FAKE_STAT_BUSY    ; indicate no longer busy
  126.     mov    bFakeData,al
  127. to1:
  128.     ret
  129. EndProc TimeoutProc
  130.  
  131.  
  132. ;IP    Port_IO_Callback - Process access to FAKE_PORT
  133. ;
  134. ;    ENTRY
  135. ;        EAX - The output value (for output instructions)
  136. ;        EBX - The handle to the current VM
  137. ;        ECX - The type of I/O operation
  138. ;        DS,ES - FLAT
  139. ;
  140. ;    EXIT
  141. ;        EAX the input value (for input instructions)
  142. ;
  143. ;    WARNINGS
  144. ;
  145. ;    NOTES
  146. ;        Note that we don't even look at the client register frame.
  147. ;
  148. ;        We simply read and increment
  149. ;
  150. ;    CALLS
  151. ;
  152. BeginProc Port_IO_Callback, NO_LOG
  153.     Dispatch_Byte_IO Fall_Through,Port_Output_Callback
  154.  
  155. Port_Input_Callback:
  156.     call    CheckOwner
  157.     jc    short ioexit
  158.     mov    al,bFakeData
  159.     or    bFakeData,FAKE_STAT_ERROR   ; clear pending error
  160. ioexit:
  161.     ret
  162.  
  163. Port_Output_Callback:
  164.     call    CheckOwner
  165.     jc    short ioexit        ; ignore I/O if not the owner
  166.     test    al,FAKE_CTL_START
  167.     jnz    short poc1        ; skip if not starting I/O
  168.     test    bFakeData,FAKE_STAT_BUSY
  169.     jz    short poc1        ; skip if already busy
  170.     test    bFakeData,FAKE_STAT_IRQ
  171.     jz    short poc1        ; skip if IRQ pending
  172.     push    eax
  173.     push    edx
  174.     and    bFakeData,NOT (FAKE_STAT_ERROR) ; presume error
  175.     mov    eax,100         ; callback in 1/10 second
  176.     mov    edx,hOwner        ; pass the owner to the callback
  177.     mov    esi,OFFSET32 TimeoutProc
  178.     VMMcall Set_VM_Time_Out
  179.     pop    edx
  180.     pop    eax
  181.     or    esi,esi
  182.     jz    short poc1        ; skip if error
  183.     and    bFakeData,NOT (FAKE_STAT_BUSY)    ; indicate busy
  184.     or    bFakeData,FAKE_STAT_ERROR   ; else, clear error indication
  185.     mov    hTimeout,esi        ; save timeout handle
  186. poc1:
  187.     test    al,FAKE_CTL_EOI
  188.     jnz    short poc2        ; skip if not sending EOI
  189.     test    bFakeData,FAKE_STAT_IRQ ; interrupt pending?
  190.     jnz    short poc2        ; skip if not
  191.     or    bFakeData,FAKE_STAT_IRQ ; indicate interrupt no longer pending
  192.     push    eax
  193.     mov    eax,hIRQ
  194.     VxDcall VPICD_Clear_Int_Request
  195.     pop    eax
  196. poc2:
  197.     ret
  198. EndProc Port_IO_Callback
  199.  
  200.  
  201. ; ECX == 0 if unmasking (enabling), ECX != 0 if masking (disabling).
  202. BeginProc VxD2_Mask_Change_Proc
  203.     call    CheckOwner
  204.     jc    short mcp9        ; ignore if not the owner
  205.     jcxz    mcp9            ; skip if unmasking (enabling)
  206. ;
  207. ; The owner is relinquishing control.  Allow another VM to sign up.
  208. ;
  209.     mov    hOwner,-1        ; clear the owner
  210.  
  211. mcp9:
  212.     ret
  213. EndProc VxD2_Mask_Change_Proc
  214.  
  215.  
  216. ; called when the ISR executes
  217. BeginProc VxD2_VInt_Proc
  218.     mov    eax,High_Pri_Device_Boost
  219.     VMMCall Adjust_Exec_Priority        ; boost priority for int processing
  220.     ret
  221. EndProc VxD2_VInt_Proc
  222.  
  223.  
  224. ; called when the ISR returns (IRETs)
  225. BeginProc VxD2_IRET_Proc
  226.     mov    eax,-(High_Pri_Device_Boost)
  227.     VMMCall Adjust_Exec_Priority        ; restore priority
  228.     ret
  229. EndProc VxD2_IRET_Proc
  230.  
  231.  
  232. ifdef DEBUG
  233. BeginProc VxD2B_Debug_Query
  234.     Trace_Out   "VxD2 has no debug command support."
  235.     clc
  236.     ret
  237. EndProc VxD2B_Debug_Query
  238. endif
  239.  
  240.  
  241. ;
  242. ;   VxD2B_Control
  243. ;
  244.  
  245. CtlDisp macro x
  246.  Control_Dispatch x, VxD2B_&x
  247.  endm
  248.  
  249. Begin_Control_Dispatch VxD2B
  250.     CtlDisp Device_Init
  251. ifdef DEBUG
  252.     CtlDisp Debug_Query
  253. endif
  254. End_Control_Dispatch VxD2B
  255.  
  256. VxD_LOCKED_CODE_ENDS
  257.  
  258.  
  259. VxD_CODE_SEG
  260. VxD_CODE_ENDS
  261.  
  262.  
  263. subttl    Initialization Data
  264. page
  265. VxD_IDATA_SEG
  266. ; put initialization-only data here
  267. VxD_IDATA_ENDS
  268.  
  269.  
  270.  
  271. subttl    VxD Initialization
  272. page
  273. VxD_ICODE_SEG
  274.  
  275. page
  276. ;EP    VxD2B_Device_Init - Non-critical Device Initialization
  277. ;
  278. ;    ENTRY
  279. ;        EBP - Client frame
  280. ;        EBX - System VM handle
  281. ;        DS,ES - FLAT
  282. ;
  283. ;    EXIT
  284. ;        SUCCESS
  285. ;        Carry clear
  286. ;        FAILURE
  287. ;        Carry set
  288. ;
  289. ;    WARNINGS
  290. ;
  291. ;    NOTES
  292. ;
  293. ;    CALLS
  294. ;
  295.  
  296. BeginProc VxD2B_Device_Init
  297.     Debug_Out "VxD2B_Device_Init"
  298.  
  299.     mov    edi,OFFSET32 IRQD
  300.     VxDcall VPICD_Virtualize_IRQ    ; Virtualize the interrupt
  301.     jc    short vdi1        ; exit if error
  302.     mov    hIRQ,eax        ; save the handle
  303.  
  304.     mov    edx,FAKE_PORT
  305.     mov    esi,OFFSET32 Port_IO_Callback
  306.     VMMCall Install_IO_Handler
  307.     VMMCall Enable_Global_Trapping    ;
  308.  
  309.     clc                ; No error
  310. vdi1:
  311.     ret
  312. EndProc VxD2B_Device_Init
  313.  
  314.  
  315.  
  316. VxD_ICODE_ENDS
  317.  
  318.  
  319. VxD_REAL_INIT_SEG
  320.  
  321. VxD2B_Real_Init LABEL FAR ; Called before Windows enters protected mode
  322.     mov ax,Device_Load_Ok    ; Allow the VxD to load
  323.     xor bx,bx        ; No EMM Exclude pages
  324.     xor si,si        ; no instance data items
  325.                 ; pass edx unmodified
  326.     ret
  327.  
  328. VxD_REAL_INIT_ENDS
  329.  
  330.     END VxD2B_Real_Init
  331.